package com.lecyon.farm.base;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.OrderItem;

import java.util.ArrayList;
import java.util.List;

/**
 * @param <T>
 * @author YaoZheng
 */
public class BaseRequestPageVo<T> extends BaseRestRequest {

    T entity;

    /**
     * 排序字段信息
     */
    private List<OrderItem> orders = new ArrayList<>();

    public List<OrderItem> getOrders() {
        return orders;
    }

    public void setOrders(List<OrderItem> orders) {
        this.orders = orders;
    }

    public T getEntity(Class<T> clazz) {
        try {
            if (entity == null) {
                return clazz.newInstance();
            } else {
                if (clazz.isInstance(entity)) {
                    return entity;
                }
                return JSONObject.parseObject(entity.toString(), clazz);
            }

        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {

        }
        return null;

    }

    public void setEntity(T entity) {
        this.entity = entity;
    }

    /**
     * 当前页码
     */
    private int pageNum = 1;

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 每页最大数量
     */
    private int pageSize = 20;

    /**
     * 排序
     */
    private String orderBy = "create_date";

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }
}
